package com.ruoyi.web.controller.inform;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.member.domain.Member;
import com.ruoyi.system.domain.inform.Inform;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.system.service.IInformService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 易告知管理Controller
 *
 * @author ruoyi
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/system/inform")
public class InformController extends BaseController {
    @Autowired
    private IInformService informService;

    /**
     * 查询里面有没有重复的数据
     */

   /*@PreAuthorize("@ss.hasPermi('system:inform:findName')")
    @GetMapping("/findName")
    public Inform findName(String names) {
        System.out.println("看看我的名字是000000 :" + names);


        return informService.findName(names);
    }*/


    /**
     * 查询易告知管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:inform:list')")
    @GetMapping("/list")
    public TableDataInfo list(Inform inform) {
        startPage();
        List<Inform> list = informService.selectInformList(inform);
        return getDataTable(list);
    }

    /**
     * 导出易告知管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:inform:export')")
    @Log(title = "易告知管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Inform inform) {
        List<Inform> list = informService.selectInformList(inform);
        ExcelUtil<Inform> util = new ExcelUtil<Inform>(Inform.class);
        util.exportExcel(response, list, "易告知管理数据");
    }

    /**
     * 获取易告知管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inform:query')")
    @GetMapping(value = "/{informId}")
    public AjaxResult getInfo(@PathVariable("informId") Integer informId) {
        return success(informService.selectInformByInformId(informId));
    }

    /**
     * 新增易告知管理
     */
    @PreAuthorize("@ss.hasPermi('system:inform:add')")
    @Log(title = "易告知管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Inform inform) {
        if (informService.insertInform(inform) == 1)
            return success();
        else
            return error("该名称已存在");
    }


    /**
     * 修改易告知管理
     */
    @PreAuthorize("@ss.hasPermi('system:inform:edit')")
    @Log(title = "易告知管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Inform inform) {
        return toAjax(informService.updateInform(inform));
    }

    /**
     * 删除易告知管理
     */
    @PreAuthorize("@ss.hasPermi('system:inform:remove')")
    @Log(title = "易告知管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{informIds}")
    public AjaxResult remove(@PathVariable Integer[] informIds) {
        if (informService.deleteInformByInformIds(informIds) == 1) {
            return success();
        } else {
            return error("选中未缴税的状态,不能删除");
        }
    }
}
